import 'dart:io';

import 'package:ladder_cash/app/com/model/request_default_params_model.dart';
import 'package:flutter/services.dart';

class DeviceDataPlugin {
  static const MethodChannel _channel = MethodChannel('DeviceDataPlugin');

  static get getDeviceInfo async {
    return await _channel.invokeMethod("getDeviceInfo");
  }

  static get requestPermission async {
    return await _channel.invokeMethod("requestPermission");
  }

  static get gotoScore async {
    return await _channel.invokeMethod("gotoScore");
  }

  static get isVPN async {
    dynamic isvpn = await _channel.invokeMethod("isVPN");
    if (isvpn is String) {
      return isvpn == "1";
    }
    return isvpn;
  }

  static get getCalendarList async {
    return await _channel.invokeMethod("getCalendarList");
  }

  static get getContacts async {
    return await _channel.invokeMethod("getContacts");
  }

  static get getAndroidId async {
    return await _channel.invokeMethod("getAndroidId");
  }

  static get getIdfv async {
    if (Platform.isIOS) return await _channel.invokeMethod("getIdfv");
    return "";
  }

  static get getGdid async {
    return await _channel.invokeMethod("getGAID");
  }

  static get getAppList async {
    return await _channel.invokeMethod("getAppList");
  }

  static get getAndroidID async {
    return await _channel.invokeMethod("getAndroidID");
  }

  ///得到短信列表
  static get smsList async {
    return await _channel.invokeMethod("getSmsList");
  }

  static get getIdfa async {
    if (Platform.isIOS) return await _channel.invokeMethod("getIdfa");
    return "";
  }

  static get openLocationSetting async {
    _channel.invokeMethod("openLocationSetting");
  }

  static Future<RequestDefaultParamsModel> get getRequestDefaultParams async {
    Map? map = await _channel.invokeMethod("getRequestDefaultParams");

    RequestDefaultParamsModel r = RequestDefaultParamsModel();
    r.appVersion = map?["appVersion"] ?? "1.0.1";
    r.deviceName = map?["deviceName"] ?? "Iphone";
    r.adid = map?["idfa"] ?? "adid";
    r.deviceId = map?["deviceId"] ?? "adfadfa";
    r.deviceOsVersion = map?["deviceOsVersion"] ?? "11.2/8.0.0";
    return r;
  }

  static Future<bool> sendBroadcastNetwork(
      String url, String? requestJsonStr, String? responseJsonStr) async {
    if (Platform.isAndroid) {
      return await _channel.invokeMethod("sendBroadcast", {
        "url": url,
        "requestJsonStr": requestJsonStr,
        "responseJsonStr": responseJsonStr
      });
    } else {
      return false;
    }
  }
}
